var events = require("events");

var Emitter = events.EventEmitter;

function Dog(name, energy){
    this.name = name;
    this.energy = energy;
    Emitter.call(this);
}

Dog.prototype = Emitter.prototype;
Dog.prototype.bark = function(){
    var eve = setInterval(() => {
        console.log(this.name + " barked! " + "energy:" + this.energy);
        this.energy--;
        if(this.energy < 0){
            clearInterval(eve);
        }
    },1000);
}
    
module.exports = Dog;